﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using SalePartial.BLL;
using SalePartial.Model;
using SalePartial.Utility;
using System.Data;
using System.Data.SqlClient;
using XunPan.Web.Globals;

public partial class Trade_trade_quote : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {

            ////■■■■■テストため■■■■
            //UserBLL.StoreUserInfoToSession("j@j10.com");
            LoginUserType type = RoleControlManager.checkUserAuthority(User.Identity.Name);
            if (type == LoginUserType.FREE_SUPPLY
                || type == LoginUserType.CERT_SUPPLY || type == LoginUserType.CERT_SUP_PUR
                || type == LoginUserType.FREE_SUP_PUR)
            {
                if (Session["s_userID_guid"] == null || Session["s_companyID_guid"] == null)
                {
                    bool result = UserBLL.StoreUserInfoToSession(User.Identity.Name);
                }
                Guid companyid = (Guid)Session["s_companyID_guid"];
                Guid userid = (Guid)Session["s_userID_guid"];


                //检查数据条件
                if (HttpContext.Current.Session["InquiryID"] != null)
                {
                    //表明页面是由其他页面transfer过来进行新报价
                    //保留对应的询盘信息
                    Guid tempId = default(Guid);
                    tempId = new Guid(HttpContext.Current.Session["InquiryID"].ToString());

                    XPInquiry inquiry = new XPInquiry();
                    XPInquiryInfo inquiryInfo = inquiry.GetXPInquiry(tempId);

                    var _with1 = inquiryInfo;
                    ltlInquiryID.Text = _with1.InquiryID.ToString();
                    ltlPartName.Text = _with1.PartName;
                    ltlPartNames.Text = _with1.PartName;
                    ltlQty1.Text = _with1.Quantity1;
                    ltlQty2.Text = _with1.Quantity2;
                    ltlQty3.Text = _with1.Quantity3;
                    ltlUnit1.Text = _with1.Unit;
                    ltlUnit2.Text = _with1.Unit;
                    ltlUnit3.Text = _with1.Unit;
                    ltlDeliverDate.Text = _with1.DeliveryDate.ToString("d");
                    ddlCurrency.SelectedValue = _with1.Currency;

                    rdpExpireDate.MinDate = DateTime.Now;

                }
                if (HttpContext.Current.Session["QuoteID"] != null)
                {
                    //表明页面是由其他event_item页面transfer到本页面进行报价单编辑操作
                    ltlQuoteID.Text = HttpContext.Current.Session["QuoteID"].ToString();
                    //加载对应quoteID的对象并初始化所有输入控件的值
                    XPQuote xpquote = new XPQuote();
                    XPQuoteInfo quoteInfo = xpquote.GetXPQuote(new Guid(ltlQuoteID.Text));

                    var _with2 = quoteInfo;
                    //检查保存和提交的状体值组合();
                    string saved = _with2.QuoteStatus.Substring(0, 1);
                    string submited = _with2.QuoteStatus.Substring(1, 1);

                    if (saved == "1" && submited == "0")
                    {
                        if (_with2.QuoteApp == "0")
                        {
                            string[] prices = _with2.UnitPriceByQty.Split("|".ToCharArray());
                            rntbUnitPrice1.Value = double.Parse(prices[0]);
                            rntbUnitPrice2.Value = double.Parse(prices[1]);
                            rntbUnitPrice3.Value = double.Parse(prices[2]);

                            prices = _with2.CostOfDeliverByQty.Split("|".ToCharArray());
                            rntbCOD1.Value = double.Parse(prices[0]);
                            rntbCOD2.Value = double.Parse(prices[1]);
                            rntbCOD3.Value = double.Parse(prices[2]);

                            prices = _with2.OtherExpenseByQty.Split("|".ToCharArray());
                            rntbOtherCost1.Value = double.Parse(prices[0]);
                            rntbOtherCost2.Value = double.Parse(prices[1]);
                            rntbOtherCost3.Value = double.Parse(prices[2]);
                            rtbOtherExpName.Text = _with2.OtherExpenseName;

                            rtbComment.Text = _with2.Comment;
                            rtbDeliverComment.Text = _with2.DeliveryComment;
                            ddlCurrency.SelectedValue = _with2.Currency;

                            

                            if (_with2.ExpireDate > System.DateTime.Now)
                            {
                                rdpExpireDate.SelectedDate = _with2.ExpireDate;
                            }
                            else
                            {
                                rdpExpireDate.SelectedDate = null;
                                rdpExpireDate.MinDate = System.DateTime.Now;
                            }
                        }
                        //预留标准或自定义报价单代码段
                        else
                        {
                            lnkAttachment.NavigateUrl = _with2.Attachment;

                            ddlCurrency.SelectedValue = _with2.Currency;

                            if (_with2.ExpireDate > System.DateTime.Now)
                            {
                                rdpExpireDate.SelectedDate = _with2.ExpireDate;
                            }
                            else
                            {
                                rdpExpireDate.SelectedDate = null;
                                rdpExpireDate.MinDate = System.DateTime.Now;
                            }

                        }

                       

                    }
                }
                //else
                //{
                //    Response.Redirect(GlobalSetting.UrlHomePage, true);
                //}

            }
            else
            {
                Response.Redirect(GlobalSetting.UrlHomePage, true);
            }
        }

    }



    protected void btnPreview_Click(object sender, System.EventArgs e)
    {
        btnReturn.Visible = btnPreview.Visible;
        btnPreview.Visible = !btnPreview.Visible;

    }


    protected void btnReturn_Click(object sender, System.EventArgs e)
    {
        btnPreview.Visible = btnReturn.Visible;
        btnReturn.Visible = !btnReturn.Visible;

    }


    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        XPQuote quote = new XPQuote();
        XPQuoteInfo quoteInfo = default(XPQuoteInfo);

        //判断是否为编辑操作

        if (ltlQuoteID.Text.Equals(""))
        {
            quoteInfo = new XPQuoteInfo();
        }
        else
        {
            try
            {
                quoteInfo = quote.GetXPQuote(new Guid(ltlQuoteID.Text));
            }
            catch (Exception ex)
            {
                return;

            }
        }

        string p = quoteInfo.QuoteID.ToString();
        Trace.Warn(p);


        switch (rtsQuote.SelectedIndex)
        {
            case 0:

                double amount1 = 0;
                double amount2 = 0;
                double amount3 = 0;

                var _with3 = quoteInfo;

                //验证必要的数据字段
                if (rdpExpireDate.SelectedDate == null)
                {
                    Trace.Warn("ExpireDate is nothing");
                    return;

                }
                else
                {
                    Trace.Warn(rdpExpireDate.SelectedDate.ToString());

                    _with3.ExpireDate = (DateTime)rdpExpireDate.SelectedDate;
                }

                if (rntbUnitPrice1.Value == null || rntbUnitPrice2.Value == null || rntbUnitPrice3.Value == null)
                {
                    Trace.Warn("Quantity is nothing");
                    return;
                }
                else
                {
                    Trace.Warn(rntbUnitPrice1.Value.ToString());

                    amount1 = (double)rntbUnitPrice1.Value * double.Parse(ltlQty1.Text);
                    amount2 = (double)rntbUnitPrice2.Value * double.Parse(ltlQty2.Text);
                    amount3 = (double)rntbUnitPrice3.Value * double.Parse(ltlQty3.Text);
                    _with3.UnitPriceByQty = rntbUnitPrice1.Value.ToString() + "|" + rntbUnitPrice2.Value.ToString() + "|" + rntbUnitPrice3.Value.ToString();
                }

                if (rntbCOD1.Value == null || rntbCOD2.Value == null || rntbCOD3.Value == null)
                {
                    Trace.Warn("COD is nothing");
                    return;
                }
                else
                {
                    Trace.Warn(rntbCOD1.Value.ToString());

                    amount1 = amount1 + (int)rntbCOD1.Value;
                    amount2 = amount2 + (int)rntbCOD2.Value;
                    amount3 = amount3 + (int)rntbCOD3.Value;
                    _with3.CostOfDeliverByQty = rntbCOD1.Value.ToString() + "|" + rntbCOD2.Value.ToString() + "|" + rntbCOD3.Value.ToString();
                }


                if (rtbOtherExpName.Text == null || string.IsNullOrEmpty(rtbOtherExpName.Text))
                {
                    Trace.Warn("OtherCostName is nothing");
                    //return;
                    _with3.OtherExpenseName = "";
                }
                else
                {
                    Trace.Warn(rtbOtherExpName.Text);
                    _with3.OtherExpenseName = rtbOtherExpName.Text;
                }

                if (rntbOtherCost1.Value == null || rntbOtherCost2.Value == null || rntbOtherCost3.Value == null)
                {
                    Trace.Warn("Othercost is nothing");
                    //return;
                     amount1 = 0;
                    amount2 = 0;
                    amount3 = 0;
                    _with3.OtherExpenseByQty = "0|0|0";
                }
                else
                {
                    Trace.Warn(rntbOtherCost1.Value.ToString());

                    amount1 = amount1 + (int)rntbOtherCost1.Value;
                    amount2 = amount2 + (int)rntbOtherCost2.Value;
                    amount3 = amount3 + (int)rntbOtherCost3.Value;
                    _with3.OtherExpenseByQty = rntbOtherCost1.Value.ToString() + "|" + rntbOtherCost2.Value.ToString() + "|" + rntbOtherCost3.Value.ToString();
                }

                _with3.Currency = ddlCurrency.SelectedValue;
                _with3.TotalAmount = amount1.ToString() + "|" + amount2.ToString() + "|" + amount3.ToString();


                //系统设置字段
                _with3.UserID = (Guid)Session["s_userID_guid"];
                _with3.CompanyID = (Guid)Session["s_companyID_guid"];
                _with3.InquiryID = new Guid(ltlInquiryID.Text);

                //报价类型-标准或者自定义
                _with3.QuoteApp = "0";
                //设置提交状态
                _with3.QuoteStatus = _with3.QuoteStatus.Remove(1, 1);
                _with3.QuoteStatus = _with3.QuoteStatus.Insert(1, "1");
                _with3.SubmitDate = DateTime.Now;
                _with3.Comment = rtbComment.Text;
                _with3.DeliveryComment = rtbDeliverComment.Text;


                //设置为空值的字段
                _with3.Attachment = "";

                if (ltlQuoteID.Text.Equals(_with3.QuoteID.ToString()))
                {
                    quote.Update(_with3);
                }
                else
                {
                    quote.Insert(_with3);
                }

                try
                {
                    XPInquiryEvent xpInqu = new XPInquiryEvent();
                    DataSet ds = xpInqu.SelectDynamic(string.Format("[VendorCompanyID] = '{0}' AND [InquiryID] = '{1}'", _with3.CompanyID, _with3.InquiryID), "");

                    DataTable dt = ds.Tables[0];
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        XPInquiryEventInfo xpevent = xpInqu.GetXPInquiryEvent(new Guid(ds.Tables[0].Rows[0]["EventID"].ToString()));

                        xpevent.EventStatus = xpevent.EventStatus.Remove(2, 1);
                        xpevent.EventStatus = xpevent.EventStatus.Insert(2, "1");
                        xpInqu.Update(xpevent);
                    }

                    XPInquiry upInquiry = new XPInquiry();

                    XPInquiryInfo inquiryInfo = upInquiry.GetXPInquiry(_with3.InquiryID);
                    var _with1 = inquiryInfo;
                    _with1.InquiryStatus = _with1.InquiryStatus.Remove(3, 1);
                    _with1.InquiryStatus = _with1.InquiryStatus.Insert(3, "1");
                    upInquiry.Update(_with1);
                }
                catch (Exception)
                {

                }
                break;

            case 1:
                //验证需要或已经上传的文件格式
                 var _with5 = quoteInfo;


                if (lnkAttachment.NavigateUrl == string.Empty)
                {
                    Trace.Warn("lnkAttachment is nothing");

                    return;

                }
                else
                {
                    //验证需要或已经上传的文件格式
                    _with5.Attachment = lnkAttachment.NavigateUrl;
                }

                 if (rdpExpireDate.SelectedDate == null)
                {
                    Trace.Warn("ExpireDate is nothing");
                    return;

                }
                else
                {
                    Trace.Warn(rdpExpireDate.SelectedDate.ToString());

                    _with5.ExpireDate = (DateTime)rdpExpireDate.SelectedDate;
                }

                 //系统设置字段
                 _with5.UserID = (Guid)Session["s_userID_guid"];
                 _with5.CompanyID = (Guid)Session["s_companyID_guid"];
                 _with5.InquiryID = new Guid(ltlInquiryID.Text);

                //报价类型-标准或者自定义
                _with5.QuoteApp = "1";

                _with5.Currency = ddlCurrency.SelectedValue;

                //设置保存状态
                _with5.QuoteStatus = _with5.QuoteStatus.Remove(1, 1);
                _with5.QuoteStatus = _with5.QuoteStatus.Insert(1, "1");
                _with5.LastSaveDate = DateTime.Now;

                if (ltlQuoteID.Text.Equals(_with5.QuoteID.ToString()))
                {
                    quote.Update(_with5);
                }
                else
                {
                    quote.Insert(_with5);
                    ltlQuoteID.Text = _with5.QuoteID.ToString();
                }

                try
                {
                    XPInquiryEvent xpInqu = new XPInquiryEvent();
                    DataSet ds = xpInqu.SelectDynamic(string.Format("[VendorCompanyID] = '{0}' AND [InquiryID] = '{1}'", _with5.CompanyID, _with5.InquiryID), "");

                    DataTable dt = ds.Tables[0];
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        XPInquiryEventInfo xpevent = xpInqu.GetXPInquiryEvent(new Guid(ds.Tables[0].Rows[0]["EventID"].ToString()));

                        xpevent.EventStatus = xpevent.EventStatus.Remove(2, 1);
                        xpevent.EventStatus = xpevent.EventStatus.Insert(2, "1");
                        xpInqu.Update(xpevent);
                    }

                    XPInquiry upInquiry = new XPInquiry();

                    XPInquiryInfo inquiryInfo = upInquiry.GetXPInquiry(_with5.InquiryID);
                    var _with1 = inquiryInfo;
                    _with1.InquiryStatus = _with1.InquiryStatus.Remove(3, 1);
                    _with1.InquiryStatus = _with1.InquiryStatus.Insert(3, "1");
                    upInquiry.Update(_with1);
                }
                catch (Exception)
                {

                }

                break;
            default:

                break;
        }

        //We need clear all values within the form before we direct to another page, for Security reason
        ResetQuoteInputControls();
        Response.Redirect("~/Trade/Supplier/SupplierInquery.aspx", true);
    }


    private void ResetQuoteInputControls()
    {

        ltlInquiryID.Text = "";
        ltlQuoteID.Text = "";
        ltlDeliverDate.Text = "";
        ltlPartName.Text = "";
        ltlPartNames.Text = "";
        ltlQty1.Text = "";
        ltlQty2.Text = "";
        ltlQty3.Text = "";
        ltlTrackingNumber.Text = "";
        ltlTrackingNumbers.Text = "";
        ltlUnit1.Text = "";
        ltlUnit2.Text = "";
        ltlUnit3.Text = "";

        rntbCOD1.Value = 0;
        rntbCOD2.Value = 0;
        rntbCOD3.Value = 0;
        rntbOtherCost1.Value = 0;
        rntbOtherCost2.Value = 0;
        rntbOtherCost3.Value = 0;
        rntbUnitPrice1.Value = 0;
        rntbUnitPrice2.Value = 0;
        rntbUnitPrice3.Value = 0;
        rdpExpireDate.Clear();

    }


    protected void btnSave_Click(object sender, System.EventArgs e)
    {
        XPQuote quote = new XPQuote();
        XPQuoteInfo quoteInfo = default(XPQuoteInfo);

        //判断是否为编辑模式

        if (ltlQuoteID.Text.Equals(""))
        {
            quoteInfo = new XPQuoteInfo();
        }
        else
        {
            try
            {
                quoteInfo = quote.GetXPQuote(new Guid(ltlQuoteID.Text));
            }
            catch (Exception ex)
            {
                return;
            }
        }

        string p = quoteInfo.QuoteID.ToString();
        Trace.Warn(p);

        switch (rtsQuote.SelectedIndex)
        {
            case 0:

                double amount1 = 0;
                double amount2 = 0;
                double amount3 = 0;

                var _with4 = quoteInfo;

                //保存阶段只需要验证有效期限字段即可
                if (rdpExpireDate.SelectedDate == null)
                {
                    Trace.Warn("ExpireDate is nothing");
                    return;

                }
                else
                {
                    Trace.Warn(rdpExpireDate.SelectedDate.ToString());

                    _with4.ExpireDate = (DateTime)rdpExpireDate.SelectedDate;
                }


                if (rntbUnitPrice1.Value == null)
                {
                    Trace.Warn("Quantity1 is nothing");
                    _with4.UnitPriceByQty = "0|";
                    amount1 = 0;
                }
                else
                {
                    Trace.Warn(rntbUnitPrice1.Value.ToString());

                    amount1 = (double)rntbUnitPrice1.Value * double.Parse(ltlQty1.Text);
                    _with4.UnitPriceByQty = rntbUnitPrice1.Value.ToString() + "|";
                }

                if (rntbUnitPrice2.Value == null)
                {
                    Trace.Warn("Quantity is nothing");

                    _with4.UnitPriceByQty = _with4.UnitPriceByQty + "0|";
                    amount2 = 0;
                }
                else
                {
                    Trace.Warn(rntbUnitPrice2.Value.ToString());

                    amount2 = (double)rntbUnitPrice2.Value * double.Parse(ltlQty2.Text);
                    _with4.UnitPriceByQty = _with4.UnitPriceByQty + rntbUnitPrice2.Value.ToString() + "|";
                }

                if (rntbUnitPrice3.Value == null)
                {
                    Trace.Warn("Quantity is nothing");

                    _with4.UnitPriceByQty = _with4.UnitPriceByQty + "0";
                    amount3 = 0;
                }
                else
                {
                    Trace.Warn(rntbUnitPrice3.Value.ToString());

                    amount3 = (double)rntbUnitPrice3.Value * double.Parse(ltlQty3.Text);
                    _with4.UnitPriceByQty = _with4.UnitPriceByQty + rntbUnitPrice3.Value.ToString();
                }

                if (rntbCOD1.Value == null)
                {
                    Trace.Warn("COD1 is nothing");

                    _with4.CostOfDeliverByQty = "0|";
                    amount1 = amount1 + 0;
                }
                else
                {
                    Trace.Warn(rntbCOD1.Value.ToString());

                    amount1 = amount1 + (double)rntbCOD1.Value;
                    _with4.CostOfDeliverByQty = rntbCOD1.Value.ToString() + "|";
                }

                if (rntbCOD2.Value == null)
                {
                    Trace.Warn("COD2 is nothing");

                    _with4.CostOfDeliverByQty = _with4.CostOfDeliverByQty + "0|";
                    amount2 = amount2 + 0;
                }
                else
                {
                    Trace.Warn(rntbCOD2.Value.ToString());

                    amount2 = amount2 + (int)rntbCOD2.Value;
                    _with4.CostOfDeliverByQty = _with4.CostOfDeliverByQty + rntbCOD2.Value.ToString() + "|";
                }

                if (rntbCOD3.Value == null)
                {
                    Trace.Warn("COD is nothing");

                    _with4.CostOfDeliverByQty = _with4.CostOfDeliverByQty + "0";
                    amount3 = amount3 + 0;
                }
                else
                {
                    Trace.Warn(rntbCOD3.Value.ToString());

                    amount3 = amount3 + (int)rntbCOD3.Value;
                    _with4.CostOfDeliverByQty = _with4.CostOfDeliverByQty + rntbCOD3.Value.ToString();
                }


                if (rtbOtherExpName.Text == null || string.IsNullOrEmpty(rtbOtherExpName.Text))
                {
                    Trace.Warn("OtherCostName is nothing");

                    _with4.OtherExpenseName = "";
                }
                else
                {
                    Trace.Warn(rtbOtherExpName.Text);
                    _with4.OtherExpenseName = rtbOtherExpName.Text;
                }

                if (rntbOtherCost1.Value == null)
                {
                    Trace.Warn("Othercost is nothing");

                    amount1 = amount1 + 0;
                    _with4.OtherExpenseByQty = "0|";
                }
                else
                {
                    Trace.Warn(rntbOtherCost1.Value.ToString());

                    amount1 = amount1 + (int)rntbOtherCost1.Value;
                    _with4.OtherExpenseByQty = rntbOtherCost1.Value.ToString() + "|";
                }

                if (rntbOtherCost2.Value == null)
                {
                    Trace.Warn("Othercost is nothing");

                    amount2 = amount2 + 0;
                    _with4.OtherExpenseByQty = _with4.OtherExpenseByQty + "0|";
                }
                else
                {
                    Trace.Warn(rntbOtherCost1.Value.ToString());


                    amount2 = amount2 + (int)rntbOtherCost2.Value;
                    _with4.OtherExpenseByQty = _with4.OtherExpenseByQty + rntbOtherCost2.Value.ToString() + "|";
                }

                if (rntbOtherCost3.Value == null)
                {
                    Trace.Warn("Othercost is nothing");

                    amount3 = amount3 + 0;
                    _with4.OtherExpenseByQty = _with4.OtherExpenseByQty + "0";
                }
                else
                {
                    Trace.Warn(rntbOtherCost1.Value.ToString());

                    amount3 = amount3 + (int)rntbOtherCost3.Value;
                    _with4.OtherExpenseByQty = _with4.OtherExpenseByQty + rntbOtherCost3.Value.ToString();
                }


                _with4.Currency = ddlCurrency.SelectedValue;
                _with4.TotalAmount = amount1.ToString() + "|" + amount2.ToString() + "|" + amount3.ToString();


                //系统设置字段
                _with4.UserID = (Guid)Session["s_userID_guid"];
                _with4.CompanyID = (Guid)Session["s_companyID_guid"];
                _with4.InquiryID = new Guid(ltlInquiryID.Text);

                //报价类型-标准或者自定义
                _with4.QuoteApp = "0";
                //设置保存状态
                _with4.QuoteStatus = _with4.QuoteStatus.Remove(0, 1);
                _with4.QuoteStatus = _with4.QuoteStatus.Insert(0, "1");
                _with4.LastSaveDate = DateTime.Now;
                _with4.Comment = rtbComment.Text;
                _with4.DeliveryComment = rtbDeliverComment.Text;


                //设置为空值的字段
                _with4.Attachment = "";

                if (ltlQuoteID.Text.Equals(_with4.QuoteID.ToString()))
                {
                    quote.Update(_with4);
                }
                else
                {
                    quote.Insert(_with4);
                    ltlQuoteID.Text = _with4.QuoteID.ToString();
                }


                break;

            case 1:

                var _with5 = quoteInfo;


                if (lnkAttachment.NavigateUrl == string.Empty)
                {
                    Trace.Warn("lnkAttachment is nothing");

                    return;

                }
                else
                {
                    //验证需要或已经上传的文件格式
                    _with5.Attachment = lnkAttachment.NavigateUrl;
                }

                 if (rdpExpireDate.SelectedDate == null)
                {
                    Trace.Warn("ExpireDate is nothing");
                    return;

                }
                else
                {
                    Trace.Warn(rdpExpireDate.SelectedDate.ToString());

                    _with5.ExpireDate = (DateTime)rdpExpireDate.SelectedDate;
                }

                 //系统设置字段
                 _with5.UserID = (Guid)Session["s_userID_guid"];
                 _with5.CompanyID = (Guid)Session["s_companyID_guid"];
                 _with5.InquiryID = new Guid(ltlInquiryID.Text);

                //报价类型-标准或者自定义
                _with5.QuoteApp = "1";

                _with5.Currency = ddlCurrency.SelectedValue;

                //设置保存状态
                _with5.QuoteStatus = _with5.QuoteStatus.Remove(0, 1);
                _with5.QuoteStatus = _with5.QuoteStatus.Insert(0, "1");
                _with5.LastSaveDate = DateTime.Now;

                if (ltlQuoteID.Text.Equals(_with5.QuoteID.ToString()))
                {
                    quote.Update(_with5);
                }
                else
                {
                    quote.Insert(_with5);
                    ltlQuoteID.Text = _with5.QuoteID.ToString();
                }

                //if (radAttachment.InvalidFiles.Count > 0)
                //{
                //    return;


                //}
                //else
                //{

                //}
                break;
            default:

                break;
        }


    }
    
    protected void btnSubmitAttachment_Click(object sender, EventArgs e)
    {
        if (radAttachment.UploadedFiles.Count > 0)
        {
            string oldfilename = radAttachment.UploadedFiles[0].GetName();
            string newfilename = null;
            string oldpath = null;
            string newpath = null;
            Trace.Warn(oldfilename);


            oldpath = Server.MapPath(radAttachment.TargetFolder) + "\\" + oldfilename;


            newfilename = FileUtility.CreateUniqueFileName(oldfilename);
            newpath = Server.MapPath(radAttachment.TargetFolder) + "\\" + newfilename;

            System.IO.File.Move(oldpath, newpath);

            lnkAttachment.Text = oldfilename;
            lnkAttachment.NavigateUrl = radAttachment.TargetFolder + "/" + newfilename;

            //将License文件的大小和类型信息存入btn中
            btnSubmitAttachment.CommandName = radAttachment.UploadedFiles[0].ContentType;
            btnSubmitAttachment.CommandArgument = radAttachment.UploadedFiles[0].ContentLength.ToString();


            lnkAttachment.Visible = btnSubmitAttachment.Visible;
            btnDeleteAttachment.Visible = btnSubmitAttachment.Visible;
            btnSubmitAttachment.Visible = !btnDeleteAttachment.Visible;
            radAttachment.Visible = !btnDeleteAttachment.Visible;
        }
    }

    protected void btnDeleteAttachment_Click(object sender, EventArgs e)
    {
        string filepath = Server.MapPath(lnkAttachment.NavigateUrl);

        System.IO.File.Delete(filepath);

        lnkAttachment.Visible = btnSubmitAttachment.Visible;
        btnDeleteAttachment.Visible = btnSubmitAttachment.Visible;
        btnSubmitAttachment.Visible = !btnDeleteAttachment.Visible;
        radAttachment.Visible = !btnDeleteAttachment.Visible;
    }
}